import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IEDA.
 * Description:
 * User:86186
 * Date:2022-09-08
 * Time:22:32
 */

/**
 * 力扣217:存在重复元素
 */

public class containsDuplicate {
    public boolean containsDuplicate(int[] nums) {
        Map<Integer,Integer> map = new HashMap<>();
        int len = nums.length;
        //传入Map
        for (int i = 0; i < len; i++) {
            int num = nums[i];
            //getOrDefault 获取ch的val,这里是0是如果加的话会覆盖所以一样
            map.put(num,map.getOrDefault(num,0)+1);
        }
        int count = 0;
        for (int i = 0; i < len; i++) {
                if (map.get(nums[i]) > 1){
                    return true;
                }
        }
        return false;
    }
}
